Audio: MFCC: Add Voice Activity Detection based on Mel spectrum#10782
Audio: MFCC: Add Voice Activity Detection based on Mel spectrum#10782singalsu wants to merge 1 commit into
Conversation
This patch adds a new mfcc_vad module that implements VAD operating on the Mel log spectrum values produced by the MFCC component. The VAD is very simple and is not very selective for voice vs. other signals. But the continuously updated background noise estimate prevents stationary noises to trigger the VAD. The algorithm tracks a per-bin noise floor (instant-down, slow-rise) and computes a A-weighted energy delta. The used weight emphasizes speech frequencies. Speech is declared when the delta exceeds a threshold (0.30 in Q9.23) with a 20-frame hangover to prevent rapid toggling. The VAD flag is inserted into the output stream as the first value after the magic header word in all format paths (S16, S24, S32). A new Kconfig option CONFIG_COMP_MFCC_VAD (depends on COMP_MFCC, default n) gates compilation of the VAD code and the stream format change. Signed-off-by: Seppo Ingalsuo <[email protected]>
|
This is still WIP. I'd like to add a better audio feature header to the fake PCM stream. In successive PRs should start to use the compress PCM type for MFCC output data. The MFCC config blob could enable for VAD mode discontinuous data. E.g. once per second background noise Mel spectrum values, for speech detected at FFT hop rate, e.g. every 10 ms. |
| /* Find j such that a_weight_hz[j] <= f_hz < a_weight_hz[j+1] */ | ||
| for (j = 0; j < A_WEIGHT_TABLE_SIZE - 2; j++) { | ||
| if (f_hz < a_weight_hz[j + 1]) | ||
| break; |
There was a problem hiding this comment.
Can this be implemented with some binary search function? It's a very small table (36 values) and this is initialization time code, not hot.
| int32_t num = (int32_t)(w1 - w0) * (f_hz - f0); | ||
| int16_t den = f1 - f0; | ||
|
|
||
| w = w0 + (int16_t)(num / den); |
There was a problem hiding this comment.
this rounds down. Is it on purpose or does it matter?
There was a problem hiding this comment.
Probably rounding would improve the accuracy. I'll check.
| /* Normalize weights so they sum to ~2^15. */ | ||
| if (sum > 0) { | ||
| for (i = 0; i < num_mel; i++) { | ||
| int32_t scaled = ((int32_t)weights[i] << 15) / sum; |
There was a problem hiding this comment.
Yes, this would be better with rounding.
| * product is Q10.38, shift right by 15 to get Q9.23 | ||
| */ | ||
| delta = mel_log[i] - vad->noise_floor[i]; | ||
| vad->noise_floor[i] += (int32_t)(((int64_t)alpha * delta) >> 15); |
There was a problem hiding this comment.
Yes, the fractional multiplications should be rounded.
| } | ||
|
|
||
| /* Shift accumulated energy from Q10.38 to Q9.23: shift right by 15 */ | ||
| energy_delta >>= 15; |
There was a problem hiding this comment.
Yep same, this would be better with rounding. Though this is not a critical part for accuracy.
This patch adds a new mfcc_vad module that implements VAD operating on the Mel log spectrum values produced by the MFCC component. The VAD is very simple and is not very selective for voice vs. other signals. But the continuously updated background noise estimate prevents stationary noises to trigger the VAD.
The algorithm tracks a per-bin noise floor (instant-down, slow-rise) and computes a A-weighted energy delta. The used weight emphasizes speech frequencies. Speech is declared when the delta exceeds a threshold (0.30 in Q9.23) with a 20-frame hangover to prevent rapid toggling.
The VAD flag is inserted into the output stream as the first value after the magic header word in all format paths (S16, S24, S32).
A new Kconfig option CONFIG_COMP_MFCC_VAD (depends on COMP_MFCC, default n) gates compilation of the VAD code and the stream format change.